package kr.co.insoft.framework;

import org.junit.runners.model.InitializationError;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.datasource.SimpleDriverDataSource;
import org.springframework.jndi.JndiTemplate;
import org.springframework.mock.jndi.SimpleNamingContextBuilder;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

public class PMSpringJUnit4ClassRunner extends SpringJUnit4ClassRunner {

	private static final Logger PMSpringJUnit4ClassRunnerLog = LoggerFactory
			.getLogger(PMSpringJUnit4ClassRunner.class);

	public PMSpringJUnit4ClassRunner(Class<?> clazz) throws InitializationError {
		super(clazz);
		try {
			bindJndi();
		} catch (Exception e) {
			PMSpringJUnit4ClassRunnerLog.error(
					"@@@@@ JNDI Bindding Exception ", e);
		}
	}

	private void bindJndi() throws Exception {
		SimpleNamingContextBuilder builder = new SimpleNamingContextBuilder();
		builder.activate();
		JndiTemplate jt = new JndiTemplate();
		SimpleDriverDataSource authDs = new SimpleDriverDataSource();
		authDs.setDriverClass(com.mysql.jdbc.Driver.class);
		authDs.setUrl("jdbc:mysql://54.178.7.77:8080/pmauth");
		authDs.setUsername("root");
		authDs.setPassword("insoft00");
		jt.bind("java:/comp/env/jdbc/pmauth", authDs);
		SimpleDriverDataSource coreDs = new SimpleDriverDataSource();
		coreDs.setDriverClass(com.mysql.jdbc.Driver.class);
		coreDs.setUrl("jdbc:mysql://54.178.7.77:8080/pmauth");
		coreDs.setUsername("root");
		coreDs.setPassword("insoft00");
		jt.bind("java:/comp/env/jdbc/pmcore", coreDs);
	}
}
